<!--
 * @Author: your name
 * @Date: 2021-05-26 15:40:36
 * @LastEditTime: 2021-06-06 21:49:00
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \遵义报名\zunyi\src\components\datePicker.vue
-->
<template>
  <el-date-picker
      v-model="value"
      type="date"
      placeholder="选择日期"
      @change="handlerChange"
      :disabled="isDisabled"
      :format="format"
    >
    </el-date-picker>
</template>

<script>
export default {
  props: {
    currentItem: {
      //当前选中日期
      required: true,
    },
    arg: {//参数符号
      type: String,
      default:"-",
      validator: (val) => {
        let reg = /[-,//,/,]/;
        return reg.test(val);
      },
    },
    isDisabled:{
        type:Boolean,
        default:false
    }
  },
  model: {
    prop: "currentItem",
    event: "change",
  },
  data() {
    return {
      value: this.currentItem ? this.toDate(this.currentItem) : "",
      format:`yyyy${this.arg}MM${this.arg}dd`//时间格式
    };
  },
  methods: {
    handlerChange(val) {
      this.$emit("change", this.$formDate(val,this.arg));
    },
    toDate(date){
        let arr = date.split(this.arg)
        return new Date(arr[0],arr[1]-1,arr[2])
    }
  }
};
</script>

<style>
</style>
